package fr.excilys.gwt.clientbundle.client;

import java.util.Arrays;
import java.util.List;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class MailManager extends Composite {

	private List<String> users = Arrays.asList("Matthieu Boniface",
			"Pierre-Yves Ricau", "Pierre Merienne");

	private Contact contact;

	private ListBox userList;

	public MailManager() {
		HorizontalPanel mainPanel = new HorizontalPanel();
		// Création de la liste des uilisateurs
		VerticalPanel usersPanel = new VerticalPanel();
		Label title = new Label("Utilisateurs");
		usersPanel.add(title);
		userList = new ListBox(true);
		userList.setVisibleItemCount(10);
		userList.setWidth("250px");
		userList.addChangeHandler(new ChangeHandler() {
			@Override
			public void onChange(ChangeEvent event) {
				int selectedIndex = userList.getSelectedIndex();
				if (selectedIndex >= 0) {
					contact.setUser(userList.getItemText(selectedIndex));
				}
			}
		});
		for (String user : users) {
			userList.addItem(user);
		}
		usersPanel.add(userList);
		mainPanel.add(usersPanel);
		// Création de la vue du contact
		contact = new Contact();
		mainPanel.add(contact);

		initWidget(mainPanel);
	}
}
